package com.nulldev.util.geolocation;

import java.net.Proxy;

import com.nulldev.util.lang.json.Json;
import com.nulldev.util.lang.json.JsonValue;
import com.nulldev.util.uri.URIUtil;
import com.nulldev.util.uri.URIUtil2.RandomUserAgent;

public class Geolocation {
	
	public static JsonValue getLocation() throws Exception {
		return getLocation(Proxy.NO_PROXY);
	}

	public static JsonValue getLocation(final Proxy p) throws Exception {
		final JsonValue parsed = Json.parse(
				URIUtil.downloadPageF(URIUtil.safeCreate("http://geoip.nekudo.com/api/"), 
						true, p, RandomUserAgent.getRandomUserAgent(), false));
		return parsed;
	}
}
